package com.stox.ui.javafx.navigator.view;

import java.util.ArrayList;
import java.util.List;

import javafx.geometry.Side;
import javafx.scene.control.TabPane;
import javafx.stage.Screen;

import org.springframework.core.OrderComparator;
import org.springframework.stereotype.Component;

import com.stox.ui.javafx.core.util.MessageSource;
import com.stox.ui.javafx.core.view.View;
import com.stox.ui.javafx.core.widget.StoxStage;
import com.stox.util.ApplicationContextUtil;

@Component
public class NavigatorView extends View{
	
	private List<AbstractNavigatorTab> navigatorTabs;
	private TabPane tabPane;
	
	public NavigatorView() {
		super(MessageSource.getMessage("Navigator"));
		tabPane = new TabPane();
		tabPane.setRotateGraphic(true);
		tabPane.setSide(Side.LEFT);
		
		navigatorTabs = new ArrayList<AbstractNavigatorTab>(ApplicationContextUtil.getApplicationContext().getBeansOfType(AbstractNavigatorTab.class).values());
		OrderComparator.sort(navigatorTabs);
		tabPane.getTabs().addAll(navigatorTabs);
		getContentPane().getChildren().add(tabPane);
	}
	
	public List<AbstractNavigatorTab> getNavigatorTabs() {
		return navigatorTabs;
	}
	
	public AbstractNavigatorTab getSelectedNavigatorTab() {
		return (AbstractNavigatorTab)tabPane.getSelectionModel().getSelectedItem();
	}
	
	@Override
	public void open() {
		setPrefWidth(Screen.getPrimary().getVisualBounds().getWidth()/5);
		setPrefHeight(StoxStage.getContentPane().getBoundsInLocal().getHeight());
		super.open();
	}

}
